import { get_commodity } from "@/api/commodity";

export default {
  namespaced: true,
  state: {
    pageNum: 1,
    pageSize: 15,
    total: "",
    rows: [],
    productName: "",
  },
  mutations: {
    // 修改
    toggle: (state, payload) => {
      state.total = payload.total;
      state.rows = payload.rows;
      console.log(state);
    },
    serach: (state, payload) => (state.productName = payload),
  },
  actions: {
    // login: async ({ state }) => {
    //     const { phone, password } = state;
    //     const { success, resultObj } = await passwordLogin({ phone, password });
    //     setToken(resultObj.token);
    //     return success;
    // },

    get: async ({ commit, state }) => {
      const { pageNum, pageSize, productName } = state;
      console.log(state);
      const data = await get_commodity({
        page: pageNum,
        limit: pageSize,
        productName: productName,
      });
      // console.log(data);
      // console.log(data);
      // return data
      commit("toggle", data);
    },
  },
};
